From 04b65aa7ad7d59585dd8722833e219b78516c9ec Mon Sep 17 00:00:00 2001 From: robertlipe Date: Mon, 22 Jul 2013 20:21:52 +0000 Subject: [PATCH] Reconcile patch set with Gerhard. Remove special case convenience for msec(); we dont' do it for hours or days...Rounding in gopal. Fix botch in ggv. --- gpsbabel/csv_util.cc | 2 +- gpsbabel/destinator.cc | 16 ++++++++-------- gpsbabel/ggv_log.cc | 2 +- gpsbabel/gopal.cc | 6 +++--- gpsbabel/magproto.cc | 2 +- gpsbabel/mapsend.cc | 2 +- gpsbabel/nmea.cc | 4 ++-- gpsbabel/reference/gopal-11-gpx.gpx | 28 ++++++++++++++-------------- gpsbabel/src/core/datetime.h | 3 --- gpsbabel/stmwpp.cc | 2 +- gpsbabel/unicsv.cc | 2 +- gpsbabel/waypt.cc | 2 +- 12 files changed, 34 insertions(+), 37 deletions(-) diff --git a/gpsbabel/csv_util.cc b/gpsbabel/csv_util.cc index 54f1d2001..32d20370d 100644 --- a/gpsbabel/csv_util.cc +++ b/gpsbabel/csv_util.cc @@ -1947,7 +1947,7 @@ xcsv_waypt_pr(const waypoint* wpt) char tbuf[24]; writetime(tbuf, sizeof(tbuf), "%s", wpt->GetCreationTime(), false); char mbuf[32]; - snprintf(mbuf, sizeof(mbuf), "%s%03d", tbuf, wpt->GetCreationTime().msec()); + snprintf(mbuf, sizeof(mbuf), "%s%03d", tbuf, wpt->GetCreationTime().time().msec()); writebuff(buff, "%s", mbuf); } break; diff --git a/gpsbabel/destinator.cc b/gpsbabel/destinator.cc index 67c0c0e9e..e7c77d2f0 100644 --- a/gpsbabel/destinator.cc +++ b/gpsbabel/destinator.cc @@ -293,7 +293,6 @@ destinator_read_trk(void) struct tm tm; char buff[20]; int date; - double time; recno++; @@ -317,7 +316,7 @@ destinator_read_trk(void) gbfseek(fin, 12 * sizeof(gbint32), SEEK_CUR); /* SAT info */ date = gbfgetint32(fin); - time = gbfgetflt(fin); + double milliseconds = gbfgetflt(fin); gbfseek(fin, 2 * 12, SEEK_CUR); /* SAT info */ @@ -330,9 +329,9 @@ destinator_read_trk(void) memset(&tm, 0, sizeof(tm)); - snprintf(buff, sizeof(buff), "%06d%.f", date, time); + snprintf(buff, sizeof(buff), "%06d%.f", date, milliseconds); strptime(buff, "%d%m%y%H%M%S", &tm); - int millisecs = (int) time % 1000; + int millisecs = lround(milliseconds) % 1000; wpt->SetCreationTime(mkgmtime(&tm), millisecs); if (wpt->fix > 0) { @@ -436,7 +435,7 @@ destinator_trkpt_disp(const waypoint* wpt) if (wpt->creation_time) { struct tm tm; - double time; + double milliseconds; int date; const time_t ct = wpt->GetCreationTime(); tm = *gmtime(&ct); @@ -444,10 +443,11 @@ destinator_trkpt_disp(const waypoint* wpt) tm.tm_year -= 100; date = ((int)tm.tm_mday * 10000) + ((int)tm.tm_mon * 100) + tm.tm_year; gbfputint32(date, fout); + milliseconds = ((int)tm.tm_hour * 10000) + + ((int)tm.tm_min * 100) + tm.tm_sec; + milliseconds = (milliseconds * 1000) + (wpt->GetCreationTime().time().msec()); - time = ((int)tm.tm_hour * 10000) + ((int)tm.tm_min * 100) + tm.tm_sec; - time = (time * 1000) + (wpt->GetCreationTime().msec()); - gbfputflt(time, fout); + gbfputflt(milliseconds, fout); } else { gbfputint32(0, fout); /* Is this invalid ? */ gbfputflt(0, fout); diff --git a/gpsbabel/ggv_log.cc b/gpsbabel/ggv_log.cc index 04efd7da0..6fc5de89d 100644 --- a/gpsbabel/ggv_log.cc +++ b/gpsbabel/ggv_log.cc @@ -238,7 +238,7 @@ ggv_log_track_head_cb(const route_head* trk) speed = waypt_speed(prev, wpt); } if (wpt->creation_time > 0) { - secs = (double)tm.tm_sec + (1000 * wpt->GetCreationTime().msec()); + secs = (double)tm.tm_sec + wpt->GetCreationTime().time().msec() / 1000.0; } gbfputint16((gbint16) latint, fout); diff --git a/gpsbabel/gopal.cc b/gpsbabel/gopal.cc index 710b80b84..48778475f 100644 --- a/gpsbabel/gopal.cc +++ b/gpsbabel/gopal.cc @@ -190,7 +190,6 @@ gopal_read(void) line=0; while ((buff = gbfgetstr(fin))) { int nfields; - unsigned long microsecs; if ((line == 0) && fin->unicode) { cet_convert_init(CET_CHARSET_UTF8, 1); } @@ -214,13 +213,14 @@ gopal_read(void) //TICK; TIME; LONG; LAT; HEIGHT; SPEED; Fix; HDOP; SAT //3801444, 080558, 2.944362, 43.262117, 295.28, 0.12964, 2, 2.900000, 3 c = csv_lineparse(str, ",", "", column++); - double millisecs = 0; + int millisecs = 0; while (c != NULL) { switch (column) { case 0: /* "-" */ /* unknown fields for the moment */ + unsigned long microsecs; sscanf(c, "%lu", µsecs); // Just save this; we'll use it on the next field. - millisecs = /*lround*/(microsecs % 1000000) / 1000.0; + millisecs = lround((microsecs % 1000000) / 1000.0); break; case 1: /* Time UTC */ sscanf(c,"%lf",&hmsd); diff --git a/gpsbabel/magproto.cc b/gpsbabel/magproto.cc index d9bdd701f..2669fd75b 100644 --- a/gpsbabel/magproto.cc +++ b/gpsbabel/magproto.cc @@ -1449,7 +1449,7 @@ void mag_track_disp(const waypoint* waypointp) tm->tm_sec; date = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year; - fracsec = lround(waypointp->GetCreationTime().msec()/10.0); + fracsec = lround(waypointp->GetCreationTime().time().msec()/10.0); } } if (!tm) { diff --git a/gpsbabel/mapsend.cc b/gpsbabel/mapsend.cc index 31c1b91e9..f479ec77a 100644 --- a/gpsbabel/mapsend.cc +++ b/gpsbabel/mapsend.cc @@ -515,7 +515,7 @@ void mapsend_track_disp(const waypoint* wpt) /* 0 centiseconds */ if (trk_version >= 30) { - c = lround(wpt->GetCreationTime().msec() / 10.0); + c = lround(wpt->GetCreationTime().time().msec() / 10.0); gbfwrite(&c, 1, 1, mapsend_file_out); } } diff --git a/gpsbabel/nmea.cc b/gpsbabel/nmea.cc index 85af2da42..a05126a11 100644 --- a/gpsbabel/nmea.cc +++ b/gpsbabel/nmea.cc @@ -1299,7 +1299,7 @@ nmea_trackpt_pr(const waypoint* wpt) if (opt_gprmc) { snprintf(obuf, sizeof(obuf), "GPRMC,%010.3f,%c,%08.3f,%c,%09.3f,%c,%.2f,%.2f,%06d,,", - (double) hms + (wpt->GetCreationTime().msec() / 1000.0), + (double) hms + (wpt->GetCreationTime().time().msec() / 1000.0), fix=='0' ? 'V' : 'A', fabs(lat), lat < 0 ? 'S' : 'N', fabs(lon), lon < 0 ? 'W' : 'E', @@ -1318,7 +1318,7 @@ nmea_trackpt_pr(const waypoint* wpt) } if (opt_gpgga) { snprintf(obuf, sizeof(obuf), "GPGGA,%010.3f,%08.3f,%c,%09.3f,%c,%c,%02d,%.1f,%.3f,M,0.0,M,,", - (double) hms + (wpt->GetCreationTime().msec() / 1000.0), + (double) hms + (wpt->GetCreationTime().time().msec() / 1000.0), fabs(lat), lat < 0 ? 'S' : 'N', fabs(lon), lon < 0 ? 'W' : 'E', fix, diff --git a/gpsbabel/reference/gopal-11-gpx.gpx b/gpsbabel/reference/gopal-11-gpx.gpx index d257e174c..4e305e9d8 100644 --- a/gpsbabel/reference/gopal-11-gpx.gpx +++ b/gpsbabel/reference/gopal-11-gpx.gpx @@ -4,7 +4,7 @@ 341.950000 - + RPT001 RPT001 RPT001 @@ -14,7 +14,7 @@ 341.990000 - + RPT002 RPT002 RPT002 @@ -24,7 +24,7 @@ 341.813000 - + RPT003 RPT003 RPT003 @@ -34,7 +34,7 @@ 341.493000 - + RPT004 RPT004 RPT004 @@ -44,7 +44,7 @@ 341.150000 - + RPT005 RPT005 RPT005 @@ -54,7 +54,7 @@ 340.210000 - + RPT006 RPT006 RPT006 @@ -64,7 +64,7 @@ 339.163000 - + RPT007 RPT007 RPT007 @@ -76,7 +76,7 @@ Tracklog Thu Jan 1 00:00:00 1970 341.950000 - + RPT001 2d 11 @@ -84,7 +84,7 @@ 341.990000 - + RPT002 2d 11 @@ -92,7 +92,7 @@ 341.813000 - + RPT003 2d 10 @@ -100,7 +100,7 @@ 341.493000 - + RPT004 2d 11 @@ -108,7 +108,7 @@ 341.150000 - + RPT005 2d 11 @@ -116,7 +116,7 @@ 340.210000 - + RPT006 2d 11 @@ -124,7 +124,7 @@ 339.163000 - + RPT007 2d 11 diff --git a/gpsbabel/src/core/datetime.h b/gpsbabel/src/core/datetime.h index d7c535683..929edae9e 100644 --- a/gpsbabel/src/core/datetime.h +++ b/gpsbabel/src/core/datetime.h @@ -75,9 +75,6 @@ public: return &t_; } - // A convenience method to return the number of milliseconds (0-999). - int msec() const { return this->time().msec(); } - // Integer form: YYMMDD int ymd() const { QDate date(this->date()); diff --git a/gpsbabel/stmwpp.cc b/gpsbabel/stmwpp.cc index 30e9e9f6c..9d3e42c7e 100644 --- a/gpsbabel/stmwpp.cc +++ b/gpsbabel/stmwpp.cc @@ -273,7 +273,7 @@ stmwpp_waypt_cb(const waypoint *wpt) gbfprintf(fout, ".%02d", 0); break; case STM_TRKPT: - gbfprintf(fout, ".%03d", wpt->GetCreationTime().msec()); + gbfprintf(fout, ".%03d", wpt->GetCreationTime().time().msec()); break; } gbfprintf(fout, ",\r\n"); diff --git a/gpsbabel/unicsv.cc b/gpsbabel/unicsv.cc index 739aeceaa..8b94a67d1 100644 --- a/gpsbabel/unicsv.cc +++ b/gpsbabel/unicsv.cc @@ -1761,7 +1761,7 @@ unicsv_waypt_disp_cb(const waypoint *wpt) } snprintf(buf, sizeof(buf), "%02d:%02d:%02d", tm.tm_hour, tm.tm_min, tm.tm_sec); - int millisecs = wpt->GetCreationTime().msec(); + int millisecs = wpt->GetCreationTime().time().msec(); if (millisecs > 0) { int len = 3; diff --git a/gpsbabel/waypt.cc b/gpsbabel/waypt.cc index 5c641b54c..6d06a3e40 100644 --- a/gpsbabel/waypt.cc +++ b/gpsbabel/waypt.cc @@ -539,7 +539,7 @@ waypt_time(const waypoint *wpt) return (double) 0; } else { - return ((double)wpt->creation_time + ((double)wpt->creation_time.msec() / 1000)); + return ((double)wpt->creation_time + ((double)wpt->creation_time.time().msec() / 1000)); } } -- 2.30.2